package com.tourscool.springboot.starter.redisson;

/**
 * Redis工具 带返回值
 *
 * @author Carlton
 * @date 2018/12/5
 */
public final class RedisExecBuilder {
    private Object returnValue;

    public static RedisExecBuilder build() {
        return new RedisExecBuilder();
    }

    public RedisExecBuilder exec(RedisValueHandler<?> handler) {
        try {
            execThrows(handler);
        } catch (Throwable throwable) {
            throw new RuntimeException(throwable);
        }
        return this;
    }

    public void execNonReturn(RedisHandler handler) {
        try {
            handler.handler(RedissonTools.getRedissonClient());
        } catch (Throwable throwable) {
            throw new RuntimeException(throwable);
        }
    }

    public RedisExecBuilder execThrows(RedisValueHandler<?> handler) throws Throwable {
        returnValue = handler.handler(RedissonTools.getRedissonClient());
        return this;
    }

    public Object returnValue() {
        return returnValue;
    }
}
